﻿/**
 * 1. 完成【包内容页面】的新建，修改，查看初始化
 * 2.【包内容页面】控件的初始化
 */
var pack = new Package();
var OperateRecordMap = new HashMap();
var partObjMap = OBJECT.PartObjMap();
var delOperateArray = [];//操作记录
var addOperateArray = [];//操作记录
var modifyOperateArray = [];//操作记录
var itemIdMap = new HashMap();//修改时，替换原有条目ID
var operateType; //全局操作表示位*op
var paramIndex = 0;
var partObjIndex = 1; //参与对象序列
packageContent = {
	getParameterId : function () {
		return paramIndex++;
	},
	getFirstPartObjSpan : function (thiss) {
		return $($(thiss).first().find("td")[1]).find("span");
	},
	getFirstPartObjId : function (thiss,attr) {
		return $($(thiss).first().find("td")[1]).find("span").attr(attr)
	},
	getFirstPartObjCd : function (thiss,attr) {
		return $($(thiss).first().find("td")[1]).find("span").attr(attr)
	},
	getActionType : function (thiss,attr) {
		return $($(thiss).prev()).find("span").attr(attr);
	},
	getActionItemId : function (thiss,attr) {
		return $(thiss).parents("tr").prev().attr(attr);
	},
	getEffectObjID : function (thiss,attr) {
		return $($(thiss).parents("tr").find("td")[4]).find("span").attr(attr);
	},
	getActionTypeSpan : function (thiss) {
		return $($("#"+thiss).next().find("td")[0]).find("span");
	},
	getEffectObjSpan : function (thiss,attr) {
		return $($("#"+thiss).next().find("td")[1]).find("span");
	},
	getItemNumberByItemId : function (itemID) {
		return $($("#"+itemID).find("td")[2]).find("div").html();
	},
	getMaxIndex : function(type,objectNumber) {
		//判定参与对象，条目序号不能重复
		var tempPack1 = $.extend(true,tempPack1,pack);
		/**重组数据结构**************start******/
		//actionItem构造成Array
		var actionItemMap = tempPack1.getActionItemMap();
		var tempParamActionRelaArray = [];
		var tempItem = [];
		if (actionItemMap!= undefined) {
			var itemValues = actionItemMap.values();
			for(var j = 0;j < actionItemMap.size();j++) {
				//actionParam构造成Array
				var itemValue = itemValues[j];
				tempItem.push(itemValues[j]);
			}
		}
		tempPack1.setActionItemMap(tempItem);
		/**重组数据结构****************end******/
		
		//1.参与对象
		if (MAXTYPE.partObj == type) {
			var _partObjSeqArray = [];
			var _objSeq = $('#pageBody div span[partobjseq]');
			$.each(_objSeq, function() {
					_partObjSeqArray.push($(this).attr('partobjseq'));
				})
			_partObjSeqArray.sort();
			
			if(_partObjSeqArray.length == 0) {
				return 1;
			} else {
				return parseInt(_partObjSeqArray[_partObjSeqArray.length-1]) + 1;
			}
		}
		
		//2.条目
		if (MAXTYPE.actionItem == type) {
			var itemArray = tempPack1.getActionItemMap();
				var number;
				var _itemSeq = [];
				$.each(itemArray, function(index, item) {
					number = item.partobjNumber;
					if((number == objectNumber) && item.getSeqNumber()) {
						_itemSeq.push(item.getSeqNumber());
					}
				})
				
				_itemSeq.sort();
				if(_itemSeq.length == 0) {
					return 1;
				} else {
					return parseInt(_itemSeq[_itemSeq.length-1]) + 1;
				}
		}
	},
	recordOperate : function (type, value) {
		if (type == PACKAGE.CONTENTOPERATE.ADD) {
			//记录操作，判断后台操作
			addOperateArray.push(value);
		}
		if (type == PACKAGE.CONTENTOPERATE.MODIFY) {

		}
		if (type == PACKAGE.CONTENTOPERATE.DEL) {
			//记录操作，判断后台操作
			if (addOperateArray.contains(value)) {
				addOperateArray.remove(value);
			}
			if (itemIdMap.containsKey(value)) {
				delOperateArray.push(itemIdMap.get(value));
			} else {
				//delOperateArray.push(value);
			}
		}
	}
};
packageContent.init = function(_operateType,initPack) {
	var objID = 1;
	var objIndex = 1;
	var objIndexTemp = 1;
	var actionIndex = 1;
	var actionIndexTemp = 0;
	var item = 0;
	var itemID = 0;
	var select = "";
	itemIdMap = new HashMap();//修改时，替换原有条目ID

	var _addEmptyActionItemToMap = function(itemID) {
		var _actionItemMap = pack.getActionItemMap();
		if (!_actionItemMap) {
			_actionItemMap = new HashMap();
		}
		var _actionItem = new PackageActionItem();
		_actionItem.setActionItemId(itemID);
		_actionItemMap.put(itemID, _actionItem);
		pack.setActionItemMap(_actionItemMap);
	}

	operateType = _operateType;
	//新增条目
	var _addActionItem = function() {
		//新增一个条目时，往Map中添加一条空的条目数据
		_addEmptyActionItemToMap(itemID);

		if (actionIndexTemp == 1) {
			var content = $("<tr>").addClass("p_c_td");
			content.attr("id", itemID);

			var test = $("#pageBody #p_" + objIndexTemp + "_0 td");
			//第一格
			content.append($(test[0]).attr("rowspan",2));
			//第二格
			content.append($(test[1]).attr("rowspan",2));
		} else {
			var content = $("<tr>").addClass("p_c_td");
			content.attr("id", itemID);
			//第一格
			content.append($("<td>").attr("rowspan",2));
			//第二格
			content.append($("<td>").attr("rowspan",2));
		}

		//第三格
		var td1 = $("<td>");
		td1.attr("rowspan",2);
		var div1 = $("<div>");

		if (actionIndex < 10) {
			div1.append("0" + actionIndex);
		} else {
			div1.append(actionIndex);
		}
		div1.addClass("p_c_td_div_item");
		td1.append(div1);
		content.append(td1);

		//第4格
		var td1 = $("<td>");
		td1.attr("colspan",3);  //合并3列：4,5,6
		var a1 = $("<a>");
		a1.attr("href","#");
		var span1 = $("<span>");
		span1.addClass("shuoming");
		span1.append("条目基本信息");
//		div1.addClass("packBase");
		td1.attr("style","cursor:pointer");
		td1.bind("click", function() {
			var itemId = $(this).parents("tr").attr("id");
			_openActionBaseInfoPage(itemId);
		});
		a1.append(span1);
		td1.append(a1);
		content.append(td1);

		//第7格
		var td1 = $("<td>");
		td1.attr("rowspan",2);
		td1.addClass("p_c_td_del");
		var a1 = $("<a>");
		var imgDel = $("<img>");

		imgDel.addClass("imgDel");
		imgDel.attr("align", "right");
		imgDel.attr("actionIndex", actionIndex);
		imgDel.attr("objIndex", objIndexTemp);
		imgDel.bind("click", function() {
			_delActionItem(this);
		});

		a1.attr("href", "#");
		a1.append(imgDel);
		td1.append(a1);
		content.append(td1);

		if (actionIndexTemp == 1) {
			$("#p_" + objIndexTemp + "_0").after(content);
			$("#p_" + objIndexTemp + "_0").remove();
			actionIndexTemp;
		} else {
			$(select).next().after(content);
		}

		//第二个tr
		content = $("<tr>").addClass("p_c_td");

		//2.4 ，动作
		var td1 = $("<td>");
		var div1 = $("<div>");
		div1.addClass('td_div');
		var a1 = $("<a>");
		var span1 = $("<span>").append("设置");
		td1.attr("style","cursor:pointer");
		td1.bind("click", function() {
			var itemId = packageContent.getActionItemId(this,"id");
			var fistItemId = "#pageBody tr[id^='"+itemId.substring(0,itemId.lastIndexOf("_"))+"_']";
			var partObjId = packageContent.getFirstPartObjId(fistItemId,"objId");
			var partObjCD = packageContent.getFirstPartObjCd(fistItemId,"id");
			_openActionTypePage(partObjId,itemId,partObjCD);
		});
		a1.attr("href", "#");
		a1.append(span1);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);
//		content.append(td1);

		//2.5格，目标对象
		var td1 = $("<td>");
		var div1 = $("<div>");
		div1.addClass('td_div');
		var a1 = $("<a>");
		var span1 = $("<span>").append("设置");
		td1.attr("style","cursor:pointer");
		td1.bind("click", function() {
			var itemId = packageContent.getActionItemId(this,"id");
			var fistItemId = "#pageBody tr[id^='"+itemId.substring(0,itemId.lastIndexOf("_"))+"_']";
			var effectObjID = $(this).find("span").attr("effectObjID");
			var partObjId = packageContent.getFirstPartObjId(fistItemId,"objId");
			var partObjCD = packageContent.getFirstPartObjCd(fistItemId,"id");
			var actionType = packageContent.getActionType(this,"actionType");
			_openEffectObjPage(itemId,effectObjID,partObjId,actionType,partObjCD);
		});
		a1.attr("href", "#");
		a1.append(span1);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);;
//		content.append(td1);

		//2.6格，参数
		var td1 = $("<td>");
		var div1 = $("<div>");
		div1.addClass('td_div');
		var a1 = $("<a>");
		var span1 = $("<span>").append("设置");
		td1.attr("style","cursor:pointer");
		td1.bind("click", function() {
			var itemId = packageContent.getActionItemId(this,"id");
			_openActionParameterPage(itemId);
		});
		a1.attr("href", "#");
		a1.append(span1);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);

		if (actionIndexTemp == 1) {
			$("#p_" + objIndexTemp + "_"+actionIndex).after(content);
			actionIndexTemp =0;
		} else {
			$(select).next().next().after(content);
		}
	}

	//删除条目
	var _delActionItem = function(thisItem) {
		var tempObjID = $(thisItem).attr("objIndex");
		var delId = "#pageBody #p_" + tempObjID + "_" + $(thisItem).attr("actionIndex")
		//var allTrs = "tr[id^='p_']";
		var delTrs = "#pageBody tr[id^='p_" + $(thisItem).attr("objIndex") + "_']";

		//客户订购 的【目标对象】被引用时，不能删除
		var objId = $($(delId).find("td")[1]).find("span").attr("objId");
		var _objNumber = $($(delId).find("td")[1]).find("span").attr("id");
		if (objId == OBJECT.PARTY) {
			var _effectObjID = $($(delId).next().find("td")[1]).find("span").attr("effectobjid");
			var ss =$('span[effectobjid="'+ _effectObjID +'"]');
			if (ss.length > 1) {
				alert('【目标对象】被引用不能删除');
				return ;
			}
		}

		if ($("#pageBody tr").size() == 2) {
			$($("#pageBody tr")[1]).remove();
			_refresh(_objNumber);
		} else if($("#pageBody tr").size() == 3) {
			$($("#pageBody tr")[1]).remove();
			$($("#pageBody tr")[1]).remove();
			_refresh(_objNumber);
		}else {
			//判断是否为本对象条目顶层
			//本层对象
			var judeID = "p_" + tempObjID + "_1";
			if (($(delId).attr("id") == $(delTrs).first().attr("id"))
					&& ($(delTrs).size() != 1)) {

				//确定下一顶层节点
				var newTopTds = $(delId).next().next().find("td");
				var newObjDiv = $(newTopTds[1]);
				var oldObjDiv = $(delId).find("td")[1];
				newObjDiv.append($(oldObjDiv).find("div"))
				//删除本层第一个条目，基本信息下移下一条目
				//if ($(delTrs).size() == ($("#pageBody tr").size()-1)) {
				var newBaseDiv = $(newTopTds[0]);
				var oldBaseDiv = $(delId).find("td")[0];
				newBaseDiv.append($(oldBaseDiv).find("div"))
				//}
			}

			//下一参与对象
//			if (($(delId).attr("id") == $(delTrs).first().attr("id"))
//					&& ($(delTrs).size() == 1)
//					&& ($(delId).next().next().length != 0)
//					&& ($(delId).next().next().attr("id").indexOf("p_") != -1)) {
//
//				//确定下一顶层节点
//				var newTopTds = $(delId).next().next().find("td");
//				var newBaseDiv = $(newTopTds[0]);
//				var oldBaseDiv = $(delId).find("td")[0];
//				newBaseDiv.append($(oldBaseDiv).find("div"))
//			}


			//删除内存对象 ：动作
			var _packActionItem;
			var actionItemMap = pack.getActionItemMap();
			if (actionItemMap != undefined) {
				pack.getActionItemMap().remove($(delId).attr("id"));
			}

			//当为参与对象最后一个条目时，保留参与对象
			if (($(delId).attr("id") == $(delTrs).first().attr("id"))
					&& ($(delTrs).size() == 1)) {
				
				$($(delId).find('td:gt(1)')).remove(); //共三个
				$(delId).append($("<td>"));
				$(delId).append($("<td>"));
				$(delId).append($("<td>"));
				$(delId).append($("<td>"));
				$(delId).append($("<td>"));
				$($(delId).find('td')).removeAttrs();
				
				$(delId).next().remove();
				$(delId).attr("id",'p_'+tempObjID+'_0')
			} else {
				$(delId).next().remove();
				$(delId).remove();
			}
			


			var id = $(thisItem).parents("tr").attr("id");
			packageContent.recordOperate(PACKAGE.CONTENTOPERATE.DEL,id);

		}
	}

	//新增对象
	var _addObj = function() {
		if (objIndex == 1) {
			objID = "p_" + objIndex + "_0";
			var content = $("<tr>").addClass("p_c_td");
			content.attr("id", objID);

			//第一格
			var td1 = $("<td>");
			var div1 = $("#p_0").find("div");
			td1.append(div1);
			content.append(td1);
		} else {
			//对象插入标志位
			objID = "p_" + (objIndex - 1) + "_0";
			select = "tr[id='" + objID + "']";

			objID = "p_" + objIndex + "_0";
			var content = $("<tr>").addClass("p_c_td");
			content.attr("id", objID);

			//第一格
			var td1 = $("<td>");
			content.append(td1);
		}

		//第二格
		var td1 = $("<td>");
		var div1 = $("<div>");
		var a1 = $("<a>");
		var span1 = $("<span style='width:70%;display:inline-block'>");
		span1.append("设置 ");
//		span1.attr("id", objIndex);
		span1.attr("id", "partObj_" + objIndex);

		var imgAdd = $("<img>");
		var imgDel = $("<img>");

		imgAdd.addClass("imgAdd");
		imgDel.addClass("imgDel");
		imgAdd.attr("align", "right");
		imgDel.attr("align", "right");
		imgAdd.attr("objIndex", objIndex);
		imgDel.attr("objIndex", objIndex);

		a1.attr("href", "#");
		a1.append(span1);
		a1.append(imgAdd);
		a1.append(imgDel);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);

		//第三格
		var td1 = $("<td>");
		content.append(td1);

		//第4格
		content.append(td1.clone());
		//第5格
		content.append(td1.clone());
		//第6格
		content.append(td1.clone());
		//第7格
		content.append(td1.clone());

		if (objIndex == 1) {
			$("#p_0").after(content);
			$("#p_0").remove()
		} else {
			$("tbody").append(content);
		}

		//事件重定义
		_addObjBindEvent(objIndex);

		objIndex++;
	}

	/**
	 *
	 * @param {Object} type 新增 | 非新增
	 * @param {Object} _objIndex
	 * @memberOf {TypeName}
	 */
	var _addObjBindEvent = function(_objIndex){
		var thiss = "#pageBody tr[id^='p_" + _objIndex + "_']";
		var partObjSpan = packageContent.getFirstPartObjSpan(thiss);

		partObjSpan.parent().find("span").bind("click", function() {
			_openPartObjPage($(this).attr("id"),$(this).attr("objid"));
		});
		partObjSpan.parent().find(".imgAdd").bind("click", function() {
			select = "#pageBody tr[id^=p_" + $(this).attr("objIndex") + "_0]";
			if ($(select).size() == 1) {
				actionIndexTemp = 1;
			}

			itemID = "p_" + $(this).attr("objIndex") + "_" + actionIndex;

			select = "#pageBody tr[id^=p_" + $(this).attr("objIndex") + "_]";
			var selectStr = $(select).last().attr("id");

			select = "#pageBody tr[id=" + selectStr + "]";

			objIndexTemp = $(this).attr("objIndex");
			_addActionItem();

			actionIndex++;

			packageContent.recordOperate(PACKAGE.CONTENTOPERATE.ADD, itemID);

		});
		partObjSpan.parent().find(".imgDel").bind("click", function() {
			_delObj(this);
		});
	}

	//删除对象以及子条目
	var _delObj = function(thisObj) {
		var delId = "#pageBody #p_" + $(thisObj).attr("objIndex")+"_0";
		var delTrs = "#pageBody tr[id^='" + "p_" + $(thisObj).attr("objIndex") + "']";

		//客户订购 的【目标对象】被引用时，不能删除
		var objId = $(thisObj).parent().find("span").attr("objId");
		if (objId == OBJECT.PARTY) {
			var isContinue = true;
			$(delTrs).each(function() {
				var ss = $(this).next().find("td")[1];
				var _effectObjID = $($(this).next().find("td")[1]).find("span").attr("effectobjid");
				var ss =$('span[effectobjid="'+ _effectObjID +'"]');
				if (ss.length > 1) {
					alert('【目标对象】被引用不能删除');
					isContinue = false;
				}
			});
			if (!isContinue) {
				return ;
			}
		}
		//客户订购 的【目标对象】被引用时，不能修改
//		if (_partObjId == OBJECT.PARTY) {
//			var ss =$('span[effectobjid="'+ _effectObjID +'"]');
//			if (ss.length>1) {
//				alert('【目标对象】被引用不能修改'); ;
//				return false;
//			}
//		}

		if ((($("#pageBody tr").size() - 1) == $(delTrs).size()*2) && ($(delId).length == 0)) {
			$(delTrs).each(function() {
				$(this).next().remove();
				$(this).remove();
			});
			_refresh();
		} else if(($("#pageBody tr").size() - 1) == $(delTrs).size()) {
			$(delTrs).remove();
			_refresh();
		}else {
			$(delTrs).each(function() {
				//判断是否为顶层
					var prev = $(this).prev();
					if (prev.attr("id") == "p_0_0") {
						//确定下一顶层节点
						if (($(delId).length != 0)) {
							var newTopTds = $(delTrs).last().next().find("td");
							var newPackageBase = $(newTopTds[0]);
							var oldPackageBase = $(this).find("td")[0];
							newPackageBase.append($(oldPackageBase).find("div"))

							$(this).remove();
						} else {
							var newTopTds = $(delTrs).last().next().next().find("td");
							var newPackageBase = $(newTopTds[0]);
							var oldPackageBase = $(this).find("td")[0];
							newPackageBase.append($(oldPackageBase).find("div"))

							$(this).next().remove();
							$(this).remove();
						}
					} else {
						//确定下一顶层节点
						if (($(delId).length != 0)) {
							$(this).remove();
						} else {
							$(this).next().remove();
							$(this).remove();
						}
					}

					//删除内存对象 ：动作
					var _packActionItem;
					var actionItemMap = pack.getActionItemMap();
					if (actionItemMap != undefined) {
						pack.getActionItemMap().remove($(this).attr("id"));
					}




					//记录操作，判断后台操作
					packageContent.recordOperate(PACKAGE.CONTENTOPERATE.DEL, $(this).attr("id"));
				});
		}
	}

	//基本信息
	var _openBaseInfoPage = function() {
		$("#openBaseInfoPage").window( {
			title : '包基本信息设置',
			width : 700,
			height : 580,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openBaseInfoPage").window('open');
		$("#openBaseInfoPage").window('refresh', 'packageBaseInfo.jsp');
	}
	
	//动作参数关联组
	var _openParamRelaGrpPage = function() {
		$("#openActionParameterPage").window( {
			title : '动作参数关联组',
			width : 700,
			height : 580,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openActionParameterPage").window('open');
		$("#openActionParameterPage").window('refresh', 'packageActionParamRelaGrp.jsp');
	}

	//参与对象
	var _openPartObjPage = function(id,objId) {
		$("#openPartObjPage").window( {
			title : '包参与对象设置',
			width : 370,
			height : 260,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openPartObjPage").window('open');
		$("#openPartObjPage").window('refresh',
				'packagePartObj.jsp?partObjNumber=' + id+'&objId='+objId);

		$("#openPartObjPage").window('move',{
				  left : 350,
				  top : 200
		});
	}
	//动作
	var _openActionTypePage = function(partObjId,actionItemId,partObjCD) {
		$("#openActionTypePage").window( {
			title : '条目动作设置',
			width : 350,
			height : 150,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openActionTypePage").window('open');
		$("#openActionTypePage").window('refresh',
				'packageActionType.jsp?actionItemId=' + actionItemId+"&partObjId="+partObjId+"&partObjCD="+partObjCD);
		$("#openActionTypePage").window('move',{
				  left : 400,
				  top : 200
		});
	}
	//动作基本信息
	var _openActionBaseInfoPage = function(actionItemId) {
		$("#openActionBaseInfoPage").window( {
			title : '条目基本信息设置',
			width : 400,
			height : 230,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openActionBaseInfoPage").window('open');
		$("#openActionBaseInfoPage").window('refresh',
				'packageActionBaseInfo.jsp?actionItemId=' + actionItemId);
	}

	//目标对象
	var _openEffectObjPage = function(actionItemId,effectObjID,partObjId,actionType,partObjCD) {
		$("#openEffectObjPage").window( {
			title : '目标对象设置',
			width : 400,
			height : 230,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openEffectObjPage").window('open');
		$("#openEffectObjPage").window('refresh',
				'pacakgeEffectObj.jsp?actionItemId=' + actionItemId+"&effectObjID="+effectObjID+"&partObjId="+partObjId
				+"&actionType="+actionType+"&partObjCD="+partObjCD);

		$("#openEffectObjPage").window('move',{
				  left : 400,
				  top : 200
		});
	}

	//条目参数
	var _openActionParameterPage = function(actionItemId) {
		$("#openActionParameterPage").window( {
			title : '条目参数设置',
			width : 600,
			height : 510,
			modal : true,
			shadow : false,
			closed : true,
			resizable : false,
			draggable : true,
			minimizable : false,
			maximizable : false
		});

		$("#openActionParameterPage").window('open');
		$("#openActionParameterPage").window('refresh',
				'packageActionParameter.jsp?actionItemId=' + actionItemId);

		$("#openActionParameterPage").window('move',{
				  left : 250,
				  top : 30
		});
	}

	//初始化baseinfo控件
	var _createBaseInfoComp = function() {
		var content = $("<tr>").addClass("p_c_td");
		content.attr("id", "p_0");

		//第一格
		var td1 = $("<td>");
		td1.attr("rowspan",2);
		var div1 = $("<div>");
		var a1 = $("<a>");
		var spanBase = $("<span style='width:90%;display:inline-block'>");
		spanBase.append("点击配置打包");
		spanBase.attr("id", "p_config");
		spanBase.bind("click", function() {
			_openBaseInfoPage();
		});
		var imgAdd = $("<img>");

		a1.attr("href", "#");
		imgAdd.addClass("imgAdd");
		imgAdd.attr("align", "right");
		imgAdd.bind("click", function() {
			_addObj();
		});

		a1.append(spanBase);
		a1.append(imgAdd);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);

		//第二格
		content.append($("<td>").attr("rowspan",2));
		content.append($("<td>").attr("rowspan",2));
		content.append($("<td>").attr("rowspan",2));
		content.append($("<td>").attr("rowspan",2));
		content.append($("<td>").attr("rowspan",2));
		content.append($("<td>").attr("rowspan",2));

		$("tr[class='p_c_head_tr']").after(content);

//		content = $("<tr>").addClass("p_c_td");
//		content.append($("<td>"));
//		content.append($("<td>"));
//		content.append($("<td>"));
//		content.append($("<td>"));
//		content.append($("<td>"));
//		content.append($("<td>"));
//		content.append($("<td>"));

//		$("#pageBody #p_0").after(content);
	}

	var _refresh = function(objNumber) {
		_createBaseInfoComp();
		objID = 1;
		objIndex = 1;
		objIndexTemp = 1;
		actionIndex = 1;
		actionIndexTemp = 0;//首次新增时判断
		item = 0;
		itemID = 0;
		select = "";

		_relocate(objNumber);
	}

	//清空所有内存对象
	var _clearAllData = function() {
		if (pack.getPackObjMap() != undefined) {
			pack.getPackObjMap().clear();
		}
		if (pack.getActionItemMap() != undefined) {
			pack.getActionItemMap().clear();
		}
		if (pack.getPackParamMap() != undefined) {
			pack.getPackParamMap().clear();
		}
	}

	//初始化已完成数据控件显示设置
	var _relocate = function(objNumber) {
		//包基本信息
		if (pack && pack.getPackageBaseInfo()) {
			$("#p_config").html(pack.getPackageBaseInfo().getName())
		}

		//包对象
		if(objNumber) {
			_addObj();
			if ((pack.getPackObjMap() != undefined)) {
				var packObj = pack.getPackObjMap().get(objNumber);

				_clearAllData();

				//存储最后一对象
				packObj.setObjectNumber("partObj_1");
				pack.getPackObjMap().put("partObj_1",packObj);
				$("#partObj_1").html(packObj.getObjectName());
				$("#partObj_1").attr("objId",packObj.getObjId());
			}
		} else {
			_clearAllData();
		}

	}

	//保存完整性校验
	var _doPackageValidate = function() {
		var _flag = false;

		_delNoNeedPackObj();

		if(_doPackDataValidate()) {
			_doPackLogicValidate();
		}
	}

	var _doPackagePreview = function() {

	}
	var _doPackageCancel = function() {
		var nextPath = 'packageManager.jsp';
		$("#path_content").attr('value', nextPath);
		$("#redirect_content").submit();
		paramIndex = 0;
	}

	//保证入库数据性校验
	var _doPackDataValidate = function() {
		var _flag = true;

		//页面元素校验：条目的完整性
		var selectItem = "#pageBody tr[id$=_0]";
		if($(selectItem).size() != 1) {
			_flag = false;
			alert("请保证存在完整性的【动作条目】");
			return _flag;
		}

		//内存：包基本信息的完整性：立即校验，保存校验
		if(!Validate.validateBaseInfo(pack.getPackageBaseInfo())) {
			_flag = false;
			return _flag;
		}
		//内存校验:数据条目存在性
		var actionItemMap = pack.getActionItemMap();
		var packObjMap = pack.getPackObjMap();
		if (actionItemMap == undefined ||
				packObjMap == undefined ||
				actionItemMap.size() == 0 ||
				packObjMap.size() == 0) {
			_flag = false;
			alert("请保证存在完整性的【动作条目】");
			return _flag;
		}

		//内存校验:完整性
		if (actionItemMap != undefined) {
				var actionItem;
				var itemValues = actionItemMap.values();
				var tempMap = new HashMap();
				for(var i = 0;i < actionItemMap.size();i++) {
					actionItem = itemValues[i];
					if (!(actionItem.partobjNumber && actionItem.effectobjNumber &&
							actionItem.getActionTypeCd() && actionItem.getDescription())) {
						_flag = false;

						var _itemNumber = packageContent.getItemNumberByItemId(actionItem.getActionItemId());
						PACK.ALERT.warn("请保证条目【"+_itemNumber+"】：【参与对象】【动作】【目标对象】【条目基本信息】共同存在");
						return _flag;
					}
				}
		}


		//被参数决定的条目必须显示
		//校验前做包对象转换
		var tempPack1 = $.extend(true,tempPack1,pack);
		var tempPack1 = relocatePackageBeforeSave(tempPack1);
		var paramActionRelaArray = tempPack1.getParamActionRelaMap();
		if (paramActionRelaArray && paramActionRelaArray.length != 0) {
			var _actionItemArrary= tempPack1.getActionItemMap();
			var _msg ="";
			$.each(paramActionRelaArray,function(index, _item) {
				var _actionItemId = _item.actionItemId;
				$.each(_actionItemArrary,function(){
					var _actionItem = this;
					if ((_actionItemId == _actionItem.actionItemId) &&
							(_actionItem.isVisible == 'N')) {
						var itemNumber;
						//p_条目ID
						if (itemIdMap.getValueFromKey(_actionItemId) != "null") {
							itemNumber = packageContent.getItemNumberByItemId(itemIdMap.getValueFromKey(_actionItemId));
						} else {
						//入库条目ID
							itemNumber = packageContent.getItemNumberByItemId(_actionItemId);
						}
						if (_msg) {
							_msg = _msg + "\n条目【"+itemNumber+"】被参数决定，不能设置为不显示";
						} else {
							_msg = "条目【"+itemNumber+"】被参数决定，不能设置为不显示";
						}

					}
				});
			});
			if (_msg) {
				alert(_msg);
				return false;
			}
		}

		//判定参与对象，条目序号不能重复
		var tempPack1 = $.extend(true,tempPack1,pack);
		var tempPack1 = relocatePackageBeforeSave(tempPack1);
		var packObjArray = tempPack1.getPackObjMap();
		//1.参与对象
		var _partObjSeqArray = [];
		var _partObjArray = [];
		for(var i =0 ;i < packObjArray.length; i++) {
			var packObj =  packObjArray[i];
			if(packObj.seq && packObj.seq != 0) {
				_partObjSeqArray.push(packObj.seq);
				_partObjArray.push(packObj);
			}
		}
		if (_partObjSeqArray.length != $.unique(_partObjSeqArray).length) {
			alert("【参与对象】序号不能重复");
			_flag = false;
		}

		//2.条目
		var itemArray = tempPack1.getActionItemMap();
		$.each(_partObjArray, function(index, _obj) {
			var number;
			var itemSeq = [];
			var _itemArray = [];
			$.each(itemArray, function(index, item) {
				number = item.partobjNumber;
				if(number == _obj.objectNumber) {
					_itemArray.push(item);
				}
			})

			$.each(_itemArray, function(index, item) {
				itemSeq.push(item.getSeqNumber());
			})

			if (itemSeq.length != $.unique(itemSeq).length) {
				alert("参与对象【"+_obj.getObjectName()+"】下【条目序号】不能重复");
				_flag = false;
			}
		})

		//当存在多个参数决定条目时，需设置
		var paramActionRela = tempPack1.getParamActionRelaMap();
		if (paramActionRela.length > 0) {
			if (paramActionRela.length == 1) {
				paramActionRela[0].grpId = 1;
			}
			var _grpIdArr = [];
			if (paramActionRela.length > 1) {
				//判断是否存在
				$.each(paramActionRela, function() {
					var _num = _isHaveDecideItem(paramActionRela,this.actionItemId);
					if((_num > 1)&& !(this.grpId)) {
						alert('存在多个参数值【决定】相同条目，请设置是否构成组');
						_flag = false;
						return _flag;
					}
					if (this.grpId) {
						_grpIdArr.push(this.grpId);
					}
				});
				
				_grpIdArr.sort();
				//对单一决定条目自动设置grpId
				var _tempGrpId = parseInt(_grpIdArr[_grpIdArr.length-1]);
				$.each(paramActionRela, function() {
					var _num = _isHaveDecideItem(paramActionRela,this.actionItemId);
					if((_num == 1)&& !(this.grpId)) {
						_tempGrpId ++;
						this.grpId = _tempGrpId;
					}
				});
			}
		}
		return _flag;
	}
	
	var _isHaveDecideItem = function(_paramActionRela,_itemId){
		var itemNum = 0;
		$.each(_paramActionRela,function() {
			if (this.actionItemId == _itemId) {
				itemNum ++;
			}
		});
		
		return itemNum;
	}
	//保证包数据逻辑的正确性
	var _doPackLogicValidate = function() {
		//入库前做包对象转换
		var tempPack1 = $.extend(true,tempPack1,pack);
		var tempPack1 = relocatePackageBeforeSave(tempPack1);
		var jsonPack = JSON.stringify(tempPack1);

		//校验前的遮罩
		ajaxLoader.action.ajaxLoaderDivEffect(TIPS.validating);
		var response = $.ajax({
			type:"POST",
			url:"../json/checkPackage.action",
			dataType:"json",
			async:false,
			data:{pack:jsonPack,operate:operateType}
		});

		ajaxLoader.action.ajaxLoaderDivClose();

		var checkResult = JSON.parse(response.responseText);
		if(checkResult.result == "true") {
			var msg = "【校验通过】！\n";
			if (checkResult.promptMsg && checkResult.promptMsg != "") {
				msg += "\n【提示信息】：\n"+checkResult.promptMsg;
			}
			alert(msg);
		} else {
			var msg = "【校验失败】:\n"+checkResult.errMsg+"\n";
			if (checkResult.promptMsg && checkResult.promptMsg != "") {
				msg += "【提示信息】：\n"+checkResult.promptMsg;
			}
			alert(msg);
		}
	}

	var _delNoNeedPackObj = function() {
		//根据动作条目MAP
			//删除未被引用的内存对象
			var _packActionItem;
			var actionItemMap = pack.getActionItemMap();
			if (actionItemMap != undefined) {
				var actionItem;
				var itemValues = actionItemMap.values();
				var tempMap = new HashMap();
				for(var i = 0;i < actionItemMap.size();i++) {
					actionItem = itemValues[i];
					//去重化入值
					tempMap.put(actionItem.partobjNumber);
					tempMap.put(actionItem.effectobjNumber);
				}

				var packageObj;
				var packObjMap = pack.getPackObjMap();
				var delObj = [];
				if (packObjMap != undefined) {
					var objValues = packObjMap.values();
					//确定需删除对象
					for(var j = 0;j < packObjMap.size();j++) {
						packageObj = objValues[j];
						if (!tempMap.containsKey(packageObj.objectNumber)) {
							delObj.push(packageObj.objectNumber);
						}
					}
					//删除
					for(var k=0;k<delObj.length; k++) {
						packObjMap.remove(delObj[k]);
					}
				}
			}
	}


	var _doPackageSave = function() {
			//入库前校验
			var _flag = _doPackDataValidate();
			if (!_flag) {
				return ;
			}

			_delNoNeedPackObj();

			//入库前做包对象转换
			var tempPack1 = $.extend(true,tempPack1,pack);
			var tempPack1 = relocatePackageBeforeSave(tempPack1);
			var jsonPack = JSON.stringify(tempPack1);

			//保存前的遮罩
			ajaxLoader.action.ajaxLoaderDivEffect(TIPS.saving);

			//复制新建保存
			if ((PACKAGE.OPERATE.NEW == operateType) ||
					(PACKAGE.OPERATE.COPYNEW == operateType)) {
				//保存
				$.ajax({
					type:"POST",
					url:"../json/savePackage.action",
					dataType:"json",
					async: false,
					data:{pack:jsonPack,operate:operateType},
					success:function(data){
						var result = data.result;
						if(result) {
							if (PACKAGE.OPERATE.COPYNEW == operateType) {
								PACK.ALERT.info("复制新建成功");
							} else {
								PACK.ALERT.info("新建成功");
							}
							_doPackageCancel();

						} else {
							alert(data.msg);
						}
					},
					error:function(){
						PACK.ALERT.error("保存出错");
					}
				});
			}
			//修改保存
			if (PACKAGE.OPERATE.MODIFY == operateType) {
				//保存
				$.ajax({
					type:"POST",
					url:"../json/modifyPackage.action",
					dataType:"json",
					async: false,
					data:{pack:jsonPack,operate:operateType},
					success:function(data){
						var result = data.result;
						if(result) {
							alert(data.msg);
							_doPackageCancel();

						} else {
							alert(data.msg);
						}
					},
					error:function(){
						PACK.ALERT.error("修改保存出错");
					}
				});
			}
			ajaxLoader.action.ajaxLoaderDivClose();

			paramIndex = 0;
	}

	var relocatePackageBeforeSave = function(packs) {
		//obj构造成Array
		var packObjMap = packs.getPackObjMap();
		var tempObj = [];
		if (packObjMap != undefined) {
			var objValues = packObjMap.values();
			for(var j = 0;j < packObjMap.size();j++) {
				tempObj.push(objValues[j]);
			}
		}
		packs.setPackObjMap(tempObj);

		//actionItem构造成Array
		var actionItemMap = packs.getActionItemMap();
		var tempParamActionRelaArray = [];
		var tempItem = [];
//		var tempActionParams = [];
		if (actionItemMap!= undefined) {
			var itemValues = actionItemMap.values();

			for(var j = 0;j < actionItemMap.size();j++) {
				//actionParam构造成Array
				var itemValue = itemValues[j];
				var _actionParamList = itemValue.getActionItemParameterList();
				if (_actionParamList!= undefined) {
					//确定需删除对象
					for(var ii = 0;ii < _actionParamList.length;ii++) {
						var _paramActionRelaList = _actionParamList[ii].getParameterActionRelaList();
						//将参数决定动作信息抽取出来放入数组
						if (_paramActionRelaList) {
							var tempParamActionRela="";
							for (var jj = 0; jj < _paramActionRelaList.length; jj++) {
								tempParamActionRela = _paramActionRelaList[jj];
								//加入存在的条目(防止被关联条目的删除)|新增条目，已有条目
								if (actionItemMap.get(tempParamActionRela.actionItemId) ||
										actionItemMap.get(itemIdMap.getValueFromKey(tempParamActionRela.actionItemId))) {
									tempParamActionRelaArray.push(tempParamActionRela);
								}
							}
//							_actionParamList[ii].setParameterActionRelaList([]);
						}
					}
				}

				tempItem.push(itemValues[j]);
			}
		}
		packs.setActionItemMap(tempItem);
		//paramActionRela构造成Array
		packs.setParamActionRelaMap(tempParamActionRelaArray);

		//packParam构造成Array
		var packParamMap = packs.getPackParamMap();
		var tempPackParam = [];
		if (packParamMap!= undefined) {
			var packParams = packParamMap.values();
			//确定需删除对象
			for(var j = 0;j < packParamMap.size();j++) {
				tempPackParam.push(packParams[j]);
			}
		}
		packs.setPackParamMap(tempPackParam);

		//修改时，记录操作
		if ((operateType == PACKAGE.OPERATE.MODIFY) ||
				(operateType == PACKAGE.OPERATE.COPYNEW)) {
			packs.setPackContentDelArray(delOperateArray);
			packs.setPackContentAddArray(addOperateArray);
			packs.setPackContentModifyArray(modifyOperateArray);

			var item; //还原原有条目ID
			var actionItemArray = packs.getActionItemMap();
			var tempItem = [];
			if ((actionItemArray!= undefined) && (actionItemArray.length != 0)) {
				for(var j = 0;j < actionItemArray.length;j++) {
					item = actionItemArray[j];
					if (itemIdMap.containsKey(item.getActionItemId())) {
						item.setActionItemId(itemIdMap.get(item.getActionItemId()));
					}
					tempItem.push(item);
				}
			}
			packs.setActionItemMap(tempItem);
		}

		return packs;
	}

	//对需要的控件绑定事件
	var _bindEventOnNeedComp = function() {
		$("#p_validate").bind("click", function() {
			_doPackageValidate();
		});
		$("#p_preview").bind("click", function() {
			_doPackagePreview();
		});
		$("#p_cancel").bind("click", function() {
			_doPackageCancel();
		});
		$("#p_save").bind("click", function() {
			_doPackageSave();
		});
		$("#p_paramRelaGrp").bind("click", function() {
			_openParamRelaGrpPage();
		});
	}

	//修改，查看：初始化重整pack
	var _initRelocatePack = function(_pack) {
		var initPack = JSON.parse(_pack);
		var partyPartObjNumber;//可以的参与对象ID

		//1.包基本信息赋值
		var _packBaseInfoAttr = CONSTANT.packBaseInfoAttr;
		var _packageBaseInfo = new PackageBaseInfo();
		for (var i=0 ; i < _packBaseInfoAttr.length; i++) {
			if (_packBaseInfoAttr[i] in initPack) {
//				alert(_packBaseInfoAttr[i] +" "+initPack[_packBaseInfoAttr[i]]);
				_packageBaseInfo[_packBaseInfoAttr[i]] = initPack[_packBaseInfoAttr[i]];
			}
		}
		pack.setPackageBaseInfo(_packageBaseInfo);

		//2.包对象赋值
		var objAttr = CONSTANT.packObjAttr;
		var objList = initPack.packageObjList;
		var _packObjMap = new HashMap();
		var _packObj;
		var packObjArray = [];
		for (var i = 0 ; i < objList.length; i++) {
			_packObj = new PackageObject();
			for (var j=0 ; j < objAttr.length; j++) {
			  if (objAttr[j] in objList[i]) {
				_packObj[objAttr[j]] = objList[i][objAttr[j]];
			  }
			}
			_packObjMap.put(_packObj.getObjectNumber(),_packObj);
			packObjArray.push(_packObj);
			if(_packObj.getObjId() == OBJECT.PARTY) {
				partyPartObjNumber = _packObj.getObjectNumber();
			}
		}
		pack.setPackObjMap(_packObjMap);

		//3.动作条目赋值
		var actionItemAttr = CONSTANT.packActionItemAttr;
		var paremeterAttr = CONSTANT.packAndItemParemter;
		var paramActionRelaAttr = CONSTANT.paramActionRelaAttr;
		var actionItemList = initPack.actionOrderItemList
		var _actionItemMap = new HashMap();
		var _packActionItem;
		var itemArray=[];
		for (var i = 0 ; i < actionItemList.length; i++) {
			_packActionItem = new PackageActionItem();
			for (var j=0 ; j < actionItemAttr.length; j++) {
			  if (actionItemAttr[j] in actionItemList[i]) {
				_packActionItem[actionItemAttr[j]] = actionItemList[i][actionItemAttr[j]];
			  }
			}

			//动作参数赋值
			var actionItemParamList = actionItemList[i].actionItemParameterList;
			if (actionItemParamList) {
				//alert(JSON.stringify(actionItemParamList));
				var _actionParamList = [];
				for (var ii = 0; ii < actionItemParamList.length; ii++) {
					var _actionParam = new ActionParameter();
					for (var jj = 0; jj < paremeterAttr.length; jj++) {
						if (paremeterAttr[jj] in actionItemParamList[ii]) {
							_actionParam[paremeterAttr[jj]] = actionItemParamList[ii][paremeterAttr[jj]];
					  	}
					}

					//参数决定动作赋值
					var paramActionRelaList = actionItemParamList[ii].parameterActionRelaList;
					if (paramActionRelaList) {
						var _actionRelaList = [];
						for (var jj = 0; jj < paramActionRelaList.length; jj++) {
							var _paramActionRela = new ParameterActionRela();
							for (var kk = 0; kk < paramActionRelaAttr.length; kk++) {
								var _actionRelaAttr = paramActionRelaAttr[kk];
								if (_actionRelaAttr in paramActionRelaList[jj]) {
									_paramActionRela[_actionRelaAttr] = paramActionRelaList[jj][_actionRelaAttr];
								}
							}
							_actionRelaList.push(_paramActionRela);
						}
						_actionParam.setParameterActionRelaList(_actionRelaList);
					}
					_actionParamList.push(_actionParam);
				}
				_packActionItem.setActionItemParameterList(_actionParamList);
			}

			itemArray.push(_packActionItem);
		}

		//1.排序参与对象，2.排序条目
		var _itemArray = [];
		//排序参与对象
		var _partObjArray = [];
		for(var i =0 ;i < packObjArray.length; i++) {
			var packObj =  packObjArray[i];
			if(packObj.seq && packObj.seq != 0) {
				_partObjArray.push(packObjArray[i]);
				partObjIndex ++;
			}
		}
		//分参与对象设序号，不设序号处理；兼容原有数据
		if (_partObjArray.length != 0) {
			_partObjArray.sort(function(a,b) {
				return a.seq.toString().localeCompare(b.seq.toString());
			})
		} else {
			_partObjArray = packObjArray;
			_partObjArray.sort(function(a,b) {
				return a.objectNumber.toString().localeCompare(b.objectNumber.toString());
			})
		}
		
		//排序条目
		$.each(_partObjArray, function(index, _obj) {
			$.each(itemArray, function(index, item) {
				var number = item.partobjNumber;
				if(number == _obj.objectNumber) {
					_itemArray.push(item);
				}
			})
			$.each(_itemArray, function(index, item) {
				itemArray.remove(item);
			})

			//根据参与对象单独排序条目
			_itemArray.sort(function(a,b) {
				return a.getSeqNumber().localeCompare(b.getSeqNumber());
			})

			itemArray = itemArray.concat(_itemArray);
			_itemArray = [];
		})
		/****************排序结束************************/

		for (var i =0;i< itemArray.length; i++) {
			_packActionItem = itemArray[i];
			_actionItemMap.put(_packActionItem.getActionItemId(),_packActionItem);
		}
		pack.setActionItemMap(_actionItemMap);

		//4.参数赋值
		var packParemterList = initPack.packageParameterList;
		var packParamMap = new HashMap();
		var _packParemeter;
		for (var i = 0 ; i < packParemterList.length; i++) {
			_packParemeter = new PackageParameter();
			for (var j=0 ; j < paremeterAttr.length; j++) {
			  if (paremeterAttr[j] in packParemterList[i]) {
				_packParemeter[paremeterAttr[j]] = packParemterList[i][paremeterAttr[j]];
			  }
			}
			packParamMap.put(_packParemeter.getParameterId(),_packParemeter);
		}
		pack.setPackParamMap(packParamMap);


	}
	//修改，查看：初始化重整pack控件
	var _initRelocatePackComp = function() {
		var trId;
		var content = $("<tr>").addClass("p_c_td");
		//第一行
		trId = "p_1_1";
		content.attr("id", trId);

		//第一格
		var td1 = $("<td>");
		td1.attr("rowspan",2);
		var div1 = $("<div>");
		var a1 = $("<a>");
		var spanBase = $("<span style='width:90%;display:inline-block'>");
		//截取包名称 >15
		if (pack.getPackageBaseInfo().getName().length > 25) {
			spanBase.append(pack.getPackageBaseInfo().getName().substr(0,25)+"...")
			spanBase.attr('title',pack.getPackageBaseInfo().getName());
		} else {
			spanBase.append(pack.getPackageBaseInfo().getName());
		}
		spanBase.attr("id", "p_config");
		spanBase.bind("click", function() {
			_openBaseInfoPage();
		});
		var imgAdd = $("<img style='width:10%'>");

		a1.attr("href", "#");
		imgAdd.addClass("imgAdd");
		imgAdd.attr("align", "right");
		imgAdd.bind("click", function() {
			_addObj();
		});

		a1.append(spanBase);
		a1.append(imgAdd);
		div1.append(a1);
		td1.append(div1);
		content.append(td1);

		//第二格 ：参与对象
		//初始化顺序，1.客户，2.CDMA
		var packObjMap = pack.getPackObjMap();
		var actionItemMap = pack.getActionItemMap();
		var actionItem;
		var itemValues = actionItemMap.values();
		var tempMap = new HashMap();
		var packPartObj;
		var packPartObj;
		var actionParamList;
		var partobjNumberPreview; //上一个参与对象|序列化显示
		var actionItemMapTemp = new HashMap();//替换条目ID
		for(var i = 0;i < actionItemMap.size();i++) {
			actionItem = itemValues[i];
			packPartObj = packObjMap.get(actionItem.partobjNumber);
			packEffectObj = packObjMap.get(actionItem.effectobjNumber);
			actionParamList = actionItem.getActionItemParameterList();
			var isShowPartObj = (partobjNumberPreview == actionItem.partobjNumber);

			//非第一行，第一格的填充
			if (actionIndex != 1) {
				//依据对象增加的序列
				if (!isShowPartObj) {
					objIndex ++;
				}

				trId = "p_" + objIndex + "_" + actionIndex;
				var content = $("<tr>").addClass("p_c_td");
				content.attr("id", trId);
				var td1 = $("<td>");
				td1.attr("rowspan",2);
				content.append(td1);
			}

			//非第一行，第二格填充
			//判断参与对象是否显示
			if (isShowPartObj) {
				var td1 = $("<td>");
				td1.attr("rowspan",2);
				content.append(td1);
			} else {
				var td1 = $("<td>");
				td1.attr("rowspan",2);
				var div1 = $("<div>");
				var a1 = $("<a>");
				var span1 = $("<span style='width:70%;display:inline-block'>");
				//参与对象序号存在时显示
				if (packPartObj.getSeq()) {
					span1.append('['+packPartObj.getSeq()+'] '+packPartObj.getObjectName());
				} else {
					span1.append(packPartObj.getObjectName());
				}
				span1.attr("id", packPartObj.objectNumber);
				span1.attr("objId", packPartObj.objId);
				span1.attr("partObjSeq",packPartObj.getSeq());

				var imgAdd = $("<img>");
				var imgDel = $("<img>");

				imgAdd.addClass("imgAdd");
				imgDel.addClass("imgDel");
				imgAdd.attr("align", "right");
				imgDel.attr("align", "right");
				imgAdd.attr("objIndex", objIndex);
				imgDel.attr("objIndex", objIndex);

				a1.attr("href", "#");
				a1.append(span1);
				a1.append(imgAdd);
				a1.append(imgDel);
				div1.append(a1);
				td1.append(div1);
				content.append(td1);

			}

			//第三格 ：条目
			var td1 = $("<td>");
			td1.attr("rowspan",2);
			var div1 = $("<div>");
			if(actionIndex < 10) {
				div1.append("0" + actionIndex);
			} else {
				div1.append(actionIndex);
			}
			div1.addClass("p_c_td_div_item");
			td1.append(div1);
			content.append(td1);

			//第4格
			var td1 = $("<td>");
			td1.attr("colspan",3);  //合并3列：4,5,6
			var a1 = $("<a>");
			a1.attr("href","#");
			var span1 = $("<span>");
			span1.addClass("shuoming");
			var itemDesc = actionItem.getDescription();
			span1.attr("title",itemDesc);
			if (itemDesc.length > 40) {
				itemDesc = itemDesc.substring(0,45)+"...";
			}
			//条目序号存在时显示
			if (actionItem.getSeqNumber()) {
				span1.append('['+actionItem.getSeqNumber()+'] '+itemDesc);
			} else {
				span1.append(itemDesc);
			}
			td1.attr("style","cursor:pointer");
			td1.bind("click", function() {
				var itemId = $(this).parents("tr").attr("id");
				_openActionBaseInfoPage(itemId);
			});
			a1.append(span1);
			td1.append(a1);
			content.append(td1);

			//第7格
			var td1 = $("<td>");
			td1.attr("rowspan",2);
			td1.addClass("p_c_td_del");
			var a1 = $("<a>");
			var imgDel = $("<img>");
			imgDel.addClass("imgDel");
			imgDel.attr("align", "right");
			imgDel.attr("actionIndex", actionIndex);
			imgDel.attr("objIndex", objIndex);
			imgDel.bind("click", function() {
				_delActionItem(this);
			});
			a1.attr("href", "#");
			a1.append(imgDel);
			td1.append(a1);
			content.append(td1);

			//加入一行上行
			$("tbody").append(content);

			content = $("<tr>").addClass("p_c_td");
//			content.attr("id", trId);
			//2.4 //动作
			var td1 = $("<td>");
			var div1 = $("<div>");
			div1.addClass('td_div');
			var a1 = $("<a>");
			var span1 = $("<span>").append(ACTION.TYPEMAP().get(actionItem.getActionTypeCd()));
			span1.attr("actionType",actionItem.getActionTypeCd());
			td1.attr("style","cursor:pointer");
			td1.bind("click", function() {
				var itemId = packageContent.getActionItemId(this,"id");
				_openActionTypePage('',itemId);
			});
			a1.attr("href", "#");
			a1.append(span1);
			div1.append(a1);
			td1.append(div1);
			content.append(td1);
	//		content.append(td1);

			//2.5格 //目标对象
			var td1 = $("<td>");
			var div1 = $("<div>");
			div1.addClass('td_div');
			var a1 = $("<a>");
			var span1 = $("<span>");
			var effectObjName = packEffectObj.getObjectName();
			span1.attr("title",effectObjName);
			span1.attr("effectObjID",packEffectObj.getObjectNumber());
			if (effectObjName!= null && effectObjName != undefined) {
				if(effectObjName.length > 18) {
					effectObjName = effectObjName.substring(0,18)+"...";
				}
			}
			span1.append(effectObjName);
			//非【新装】增加事件
			if (ACTION.TYPE.NEW != actionItem.getActionTypeCd()) {
				td1.attr("style","cursor:pointer");
				td1.bind("click", function() {
					var itemId = packageContent.getActionItemId(this,"id");
					var fistItemId = "#pageBody tr[id^='"+itemId.substring(0,itemId.lastIndexOf("_"))+"_']";
					var effectObjID = $(this).find("span").attr("effectObjID");
					var partObjId = packageContent.getFirstPartObjId(fistItemId,"objId");
					var partObjCD = packageContent.getFirstPartObjCd(fistItemId,"id")
					var actionType = packageContent.getActionType(this,"actionType")
					_openEffectObjPage(itemId,effectObjID,partObjId,actionType,partObjCD);
				});
			}
			
			a1.attr("href", "#");
			a1.append(span1);
			div1.append(a1);
			td1.append(div1);
			content.append(td1);;
	//		content.append(td1);

			//2.6格 //参数
			var td1 = $("<td>");
			var div1 = $("<div>");
			div1.addClass('td_div');
			var a1 = $("<a>");
			var span1 = $("<span>").append("设置");
			if (actionParamList && actionParamList.length > 0) {
				var firstParamName = actionParamList[0].getName();
				var allParamName = firstParamName;
				if (actionParamList.length > 1) {
					$.each(actionParamList, function(index, actionParam) {
						if (index != 0) {
							allParamName += "，" + actionParam.getName();
						}
					});
					span1.attr("title", allParamName);
					var tempName = firstParamName + "...更多";
					if(tempName.length > 10) {
						firstParamName = firstParamName.substring(0,10)+"...更多";
					} else {
						firstParamName = tempName;
					}
					span1.html(firstParamName);
				} else {
					span1.attr("title", firstParamName);
					if(firstParamName.length > 10) {
						firstParamName = firstParamName.substring(0,12)+"...";
					}
					$(span1).text(firstParamName);
				}
			}
			td1.attr("style","cursor:pointer");
			td1.bind("click", function() {
				var itemId = packageContent.getActionItemId(this,"id");
				_openActionParameterPage(itemId);
			});
			a1.attr("href", "#");
			a1.append(span1);
			div1.append(a1);
			td1.append(div1);
			content.append(td1);

			//加入一行下行
			$("tbody").append(content);

			if (!isShowPartObj){
				_addObjBindEvent(objIndex);
			}


			//替换条目ID
			itemIdMap.put(trId,actionItem.getActionItemId())
			actionItem.setActionItemId(trId);
			actionItemMapTemp.put(trId,actionItem);
			partobjNumberPreview = actionItem.partobjNumber;
			actionIndex ++;
		}
		pack.setActionItemMap(actionItemMapTemp);
		objIndex ++;
	}
	
	//查看时屏蔽某些控件
	var _disbaleCompWhenShow = function() {
		$("#p_save").attr('style','display:none');
//		$("#p_paramRelaGrp").attr('style','display:none');
	}
	
	//默认加载
	var _load = function(initPack) {
		//新增
		if (operateType == PACKAGE.OPERATE.NEW) {
			_createBaseInfoComp();
		}
		//修改
		if (operateType == PACKAGE.OPERATE.MODIFY ||
				operateType == PACKAGE.OPERATE.COPYNEW) {
			_initRelocatePack(initPack);
			_initRelocatePackComp();
		}
		//查看
		if (operateType == PACKAGE.OPERATE.SHOW) {
			_initRelocatePack(initPack);
			_initRelocatePackComp();
			_disbaleCompWhenShow();
		}
		_bindEventOnNeedComp();

	}

	_load(initPack);
}